//C13:ep13_4.c://1- output the data to console. 
// 2- copy data to another file.
#include <stdio.h>

int main(void)
{
    FILE *fp1, *fp2;
    fp1 = fopen("file1.txt", "r");
    fp2 = fopen("file2.txt", "w");
    if(fp1 == NULL)
    {
        fprintf(stderr, "file1.txt open failed!");
    }

    if(fp2 == NULL)
    {
        fprintf(stderr, "file2.txt open failed!");
    }

    while(!feof(fp1))
    {
        putchar(getc(fp1));
    }

    // pointer to the begin of file1.txt;
    rewind(fp1);
    while(!feof(fp1))
    {
        fputc(getc(fp1), fp2);
    }

    fclose(fp1);
    fclose(fp2);
    return 0;
}
